package org.ansj.lucene;

import java.io.Reader;
import java.util.Set;

import org.ansj.library.UserDefineLibrary;
import org.ansj.util.newWordFind.LearnTool;
import org.apache.lucene.analysis.ReusableAnalyzerBase;
import org.apache.lucene.analysis.Tokenizer;
import org.elasticsearch.common.settings.Settings;

/**
 * 
 * @author Spancer.ray
 * 
 */
public class AnsjAnalyzer extends ReusableAnalyzerBase {

	public Set<String> filter;

	public boolean pstemming = false;;

	/**
	 * 
	 * @param filter
	 * @param pstemming
	 */
	public AnsjAnalyzer(Set<String> filter, boolean pstemming) {
		super();
		this.filter = filter;
		this.pstemming = pstemming;
	}

	public AnsjAnalyzer(boolean pstemming) {
		this.pstemming = pstemming;
	}

	public AnsjAnalyzer() {
		super();
	}

	public AnsjAnalyzer(Settings settings) {
		UserDefineLibrary.init(settings);
	}

	@Override
	protected TokenStreamComponents createComponents(String fieldName,
			Reader reader) {
		final Tokenizer source = new AnsjTokenizer(reader, filter, pstemming,
				new LearnTool());
		return new TokenStreamComponents(source);
	}

}